package com.wz.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wz.entity.Dep;
import com.wz.entity.Empage;
import com.wz.service.impl.DepServiceImpl;
import com.wz.service.impl.EmpageServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("empage")
public class EmpageController {
    @Autowired
    private EmpageServiceImpl empageService;

    @RequestMapping("addEmpAge")
    public String toadd(){
        return "addEmpAge";
    }
    private PageInfo<Empage> getPageInfo(){
        PageHelper.startPage(1, 3);
        List<Empage> empages = empageService.findEmpage();
        PageInfo<Empage> pageInfo = new PageInfo<>(empages);//使用PageInfo包装类
        return pageInfo;

    }


    @RequestMapping("/delete/{empno}")
    public String delte(@PathVariable("empno") String empno, HttpServletRequest request) {
        empageService.delete(empno);
        System.out.println("delete方法执行成功！！");
        request.getSession().setAttribute("pageInfo2",getPageInfo());
        return "showdep";
    }

    @PostMapping("addEmp")
    public String addDep(Empage empage, HttpServletRequest request) {
        empageService.save(empage);
        request.getSession().setAttribute("pageInfo2",getPageInfo());
        return "showdep";
    }
}
